import Vue from 'vue'
import VueRouter from 'vue-router'
import GuardService from '@/service/guard';

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'Login',
    component:() => import('@/views/login/index.vue')
  },
  {
    path: '/',
    alias:'/home',
    meta:{ keepAlive:true,homePage:true },
    name: 'Home',
    component:() => import('@/views/home/index.vue')
  },
  {
    path: '/oa',
    name: 'OA',
    meta:{ keepAlive:true,homePage:true },
    component:() => import('@/views/oa/index.vue')
  },
  {
    path: '/user',
    name: 'User',
    meta:{ keepAlive:true,homePage:true },
    component:() => import('@/views/user/index.vue')
  },
  {
    path: '/details/:id',
    name: 'Details',
    component:() => import('@/views/details/index.vue')
  },
  {
    path: '/search',
    name: 'Search',
    meta: { animationGo:'slide-rightin-leftout', animationBack:'slide-leftin-rightout' },
    component:() => import('@/views/search/index.vue')
  },
  {
    path:'/enterprisestructurechoosenone',
    name: 'EnterpriseStructureChooseone',
    component:() => import('@/components/enterprisestructure/choosenone/index.vue'),
  },
  {
    path:'/ordercreate/:templateData',
    name: 'Ordercreate',
    meta:{ keepAlive:true},
    component:() => import('@/components/order/create/index.vue'),
  },
  {
    path: '/settings',
    name: 'Settings',
    component:() => import('@/views/user/settings/index.vue')
  },
]

const router = new VueRouter({
  routes,
})


router.beforeEach((to,from,next) => {
  if(!GuardService.isLogginIned()) {
    if(to.path === '/login') {
      next();
    } else {
      next({path:'/login'});
    }
  } else {
    next();
  }
})

export default router